home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / plot.h < prev    next >
C/C++ Source or Header  |  1993-09-15  |  16KB  |  608 lines

  1. /*
  2.  * $Id: plot.h%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - plot.h */
  7. /*
  8.  * Copyright (C) 1986 - 1993   Thomas Williams, Colin Kelley
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software is provided "as is" without express or implied warranty.
  21.  * 
  22.  *
  23.  * AUTHORS
  24.  * 
  25.  *   Original Software:
  26.  *     Thomas Williams,  Colin Kelley.
  27.  * 
  28.  *   Gnuplot 2.0 additions:
  29.  *       Russell Lang, Dave Kotz, John Campbell.
  30.  *
  31.  *   Gnuplot 3.0 additions:
  32.  *       Gershon Elber and many others.
  33.  * 
  34.  * There is a mailing list for gnuplot users. Note, however, that the
  35.  * newsgroup 
  36.  *    comp.graphics.gnuplot 
  37.  * is identical to the mailing list (they
  38.  * both carry the same set of messages). We prefer that you read the
  39.  * messages through that newsgroup, to subscribing to the mailing list.
  40.  * (If you can read that newsgroup, and are already on the mailing list,
  41.  * please send a message info-gnuplot-request@dartmouth.edu, asking to be
  42.  * removed from the mailing list.)
  43.  *
  44.  * The address for mailing to list members is
  45.  *       info-gnuplot@dartmouth.edu
  46.  * and for mailing administrative requests is 
  47.  *       info-gnuplot-request@dartmouth.edu
  48.  * The mailing list for bug reports is 
  49.  *       bug-gnuplot@dartmouth.edu
  50.  * The list of those interested in beta-test versions is
  51.  *       info-gnuplot-beta@dartmouth.edu
  52.  */
  53.  
  54. #define PROGRAM "G N U P L O T"
  55. #define PROMPT "gnuplot> "
  56. #if defined(AMIGA_SC_6_1) || defined(AMIGA_AC_5)
  57. #define SHELL "NewShell"
  58. #else /* AMIGA */
  59. #ifdef ATARI
  60. #define SHELL "gulam.prg"
  61. #else /* ATARI */
  62. #ifdef OS2
  63. #define SHELL "c:\\cmd.exe"
  64. #else /*OS2 */
  65. #define SHELL "/bin/sh"        /* used if SHELL env variable not set */
  66. #endif /*OS2 */
  67. #endif /* ATARI */
  68. #endif /* AMIGA  */
  69.  
  70. #if defined(__unix__) && !defined(unix)
  71. #define unix
  72. #endif
  73.  
  74. #define SAMPLES 100        /* default number of samples for a plot */
  75. #define ISO_SAMPLES 10        /* default number of isolines per splot */
  76. #define ZERO    1e-8        /* default for 'zero' set option */
  77.  
  78. #ifndef TERM
  79. /* default terminal is "unknown"; but see init_terminal */
  80. #define TERM "unknown"
  81. #endif
  82.  
  83. #define TRUE 1
  84. #define FALSE 0
  85.  
  86.  
  87. #define Pi 3.141592653589793
  88. #define DEG2RAD (Pi / 180.0)
  89.  
  90.  
  91. #define MIN_CRV_POINTS 100        /* minimum size of points[] in curve_points */
  92. #define MIN_SRF_POINTS 1000        /* minimum size of points[] in surface_points */
  93.  
  94. #define MAX_LINE_LEN 1024    /* maximum number of chars allowed on line */
  95. #define MAX_TOKENS 400
  96. #define MAX_ID_LEN 50        /* max length of an identifier */
  97.  
  98.  
  99. #define MAX_AT_LEN 150        /* max number of entries in action table */
  100. #define STACK_DEPTH 100
  101. #define NO_CARET (-1)
  102.  
  103. #ifdef MSDOS
  104. #define MAX_NUM_VAR    3    /* Ploting projection of func. of max. five vars. */
  105. #else
  106. #define MAX_NUM_VAR    5    /* Ploting projection of func. of max. five vars. */
  107. #endif
  108.  
  109. #define MAP3D_CARTESIAN        0    /* 3D Data mapping. */
  110. #define MAP3D_SPHERICAL        1
  111. #define MAP3D_CYLINDRICAL    2
  112.  
  113. #define CONTOUR_NONE    0    /* Where to place contour maps if at all. */
  114. #define CONTOUR_BASE    1
  115. #define CONTOUR_SRF    2
  116. #define CONTOUR_BOTH    3
  117.  
  118. #define CONTOUR_KIND_LINEAR    0 /* See contour.h in contours subdirectory. */
  119. #define CONTOUR_KIND_CUBIC_SPL    1
  120. #define CONTOUR_KIND_BSPLINE    2
  121.  
  122. #define LEVELS_AUTO            0        /* How contour levels are set */
  123. #define LEVELS_INCREMENTAL    1        /* user specified start & incremnet */
  124. #define LEVELS_DISCRETE        2        /* user specified discrete levels */
  125. #define MAX_DISCRETE_LEVELS   30
  126.  
  127. #define ANGLES_RADIANS    0
  128. #define ANGLES_DEGREES    1
  129.  
  130.  
  131. #if defined(AMIGA_SC_6_1) || defined(AMIGA_AC_5)
  132. #define OS "Amiga "
  133. #endif
  134.  
  135. #ifdef OS2
  136. #ifdef unix
  137. #undef unix    /* GCC might declare this */
  138. #define OS "OS/2"
  139. #endif
  140. #endif  /* OS2 */
  141.  
  142. #ifdef vms
  143. #define OS "VMS "
  144. #endif
  145.  
  146. #ifdef linux
  147. #define OS "Linux "
  148. #else
  149. #ifdef unix
  150. #define OS "unix "
  151. #endif
  152. #endif
  153.  
  154. #ifdef _WINDOWS
  155. #define _Windows
  156. #endif
  157.  
  158. #ifdef DOS386
  159. #define OS "DOS 386 "
  160. #endif
  161. #ifdef _Windows
  162. #define OS "MS-Windows "
  163. #else
  164. #ifdef MSDOS
  165. #ifdef unix    /* __EMX__ and DJGPP may set this */
  166. #undef OS
  167. #undef unix
  168. #endif
  169. #define OS "MS-DOS "
  170. #endif
  171. #endif
  172.  
  173.  
  174. #ifdef ATARI
  175. #define OS "TOS "
  176. #endif
  177.  
  178. #ifndef OS
  179. #define OS ""
  180. #endif
  181.  
  182.  
  183. /* To access curves larger than 64k, MSDOS needs to use huge pointers */
  184. #if (defined(__TURBOC__) && defined(MSDOS)) || (defined(_Windows) && !defined(WIN32))
  185. #define GPHUGE huge
  186. #define GPFAR far
  187. #else
  188. #define GPHUGE
  189. #define GPFAR
  190. #endif
  191.  
  192.  
  193. /*
  194.  * Note about VERYLARGE:  This is the upper bound double (or float, if PC)
  195.  * numbers. This flag indicates very large numbers. It doesn't have to 
  196.  * be the absolutely biggest number on the machine.  
  197.  * If your machine doesn't have HUGE, or float.h,
  198.  * define VERYLARGE here. 
  199.  *
  200.  * This is a mess.  If someone figures out how to clean this up, please
  201.  *    diff -c  of your fixes
  202.  *
  203.  *
  204.  * example:
  205. #define VERYLARGE 1e37
  206.  */
  207.  
  208. #ifdef ATARI
  209. #include <stdlib.h>        /* Prototyping used !! 'size_t' */
  210. #include <stdio.h>
  211. #include <string.h>
  212. #include <math.h>
  213. #define VERYLARGE    HUGE_VAL
  214. #else  /* not ATARI */
  215. #if defined(MSDOS) || defined(_Windows)
  216. #include <float.h>
  217. #define VERYLARGE (FLT_MAX/2 -1)
  218. #else  /* not MSDOS || _Windows */
  219. #if defined( vms ) || defined( _CRAY ) || defined( NEXT ) || defined(__osf__) || defined( OS2 ) || defined(__EMX__) || defined( DOS386) || defined(KSR)
  220. #include <float.h>
  221. #if defined ( NEXT )  /* bug in NeXT OS 2.0 */
  222. #if defined ( DBL_MAX)
  223. #undef DBL_MAX
  224. #endif
  225. #define DBL_MAX 1.7976931348623157e+308 
  226. #undef HUGE
  227. #define HUGE    DBL_MAX
  228. #undef HUGE_VAL
  229. #define HUGE_VAL DBL_MAX
  230. #endif /* not NEXT but CRAY, VMS or OSF */
  231. #define VERYLARGE (DBL_MAX/2 -1)
  232. #else  /* not vms, CRAY, NEXT, OS/2 or OSF */
  233. #ifdef AMIGA_AC_5
  234. #include <math.h>
  235. #define VERYLARGE (HUGE/2 -1)
  236. #else /* not AMIGA_AC_5 */
  237. #ifdef AMIGA_SC_6_1
  238. #include <float.h>
  239. #ifndef HUGE
  240. #define HUGE DBL_MAX
  241. #endif
  242. #define VERYLARGE (HUGE/2 -1)
  243. #else /* !AMIGA_SC_6_1 */
  244. /* #include <float.h> */
  245. #ifdef ISC22
  246. #include <float.h>
  247. #ifndef HUGE
  248. #define HUGE DBL_MAX
  249. #endif
  250. #endif /* ISC22 */
  251. /* This is the default */
  252. #ifndef HUGE
  253. #define HUGE DBL_MAX
  254. #endif
  255. #define VERYLARGE (HUGE/2 -1)
  256. /* default */
  257. #endif /* !AMIGA_SC_6_1 */
  258. #endif /* !AMIGA_AC_5 */
  259. #endif /* !VMS !CRAY !NEXT */
  260. #endif /* !MSDOS || !_Windows */
  261. #endif /* !ATARI */
  262.  
  263. #ifdef AMIGA_SC_6_1
  264. /* Get function prototypes */
  265. #include <stdio.h>
  266. #include <stdlib.h>
  267. #include <string.h>
  268. #include <math.h>
  269. #endif /* AMIGA_SC_6_1 */
  270.  
  271. #define END_OF_COMMAND (c_token >= num_tokens || equals(c_token,";"))
  272.  
  273. #ifdef vms
  274.  
  275.  
  276. #define is_comment(c) ((c) == '#' || (c) == '!')
  277. #define is_system(c) ((c) == '$')
  278.  
  279.  
  280. #else /* vms */
  281.  
  282. #define is_comment(c) ((c) == '#')
  283. #define is_system(c) ((c) == '!')
  284.  
  285. #endif /* vms */
  286.  
  287. /* If you don't have vfork, then undefine this */
  288. #if defined(NOVFORK) || defined(MSDOS) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  289. # undef VFORK
  290. #else
  291. # ifdef unix
  292. #  define VFORK
  293. # endif
  294. #endif
  295.  
  296. /* 
  297.  * memcpy() comes by many names. The default is now to assume bcopy, 
  298.  * since it is the most common case. Define 
  299.  *  MEMCPY to use memcpy(), 
  300.  *  vms to use the vms function,
  301.  *  NOCOPY to use a handwritten version in parse.c
  302.  */
  303. #ifdef vms
  304. # define memcpy(dest,src,len) lib$movc3(&len,src,dest)
  305. #else
  306. # if defined(MEMCPY) || defined(MSDOS) || defined (ATARI) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  307.    /* use memcpy directly */
  308. # else 
  309. #  ifdef NOCOPY
  310.     /* use the handwritten memcpy in parse.c */
  311. #  else
  312.     /* assume bcopy is in use */
  313. #   define memcpy(dest,src,len) bcopy(src,dest,len)
  314. #  endif /* NOCOPY */
  315. # endif /* MEMCPY || MSDOS */
  316. #endif /* vms */
  317.  
  318. /*
  319.  * In case you have MEMSET instead of BZERO. If you have something 
  320.  * else, define bzero to that something.
  321.  */
  322. #if defined(MEMSET) || defined(MSDOS) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  323. #define bzero(dest,len)  (void)(memset(dest, 0, len))
  324. #endif /* MEMSET || MSDOS */
  325.  
  326. #define top_of_stack stack[s_p]
  327.  
  328. typedef int TBOOLEAN;
  329.  
  330. #ifdef __ZTC__
  331. typedef int (*FUNC_PTR)(...);
  332. #else
  333. typedef int (*FUNC_PTR)();
  334. #endif
  335.  
  336. enum operators {
  337.     PUSH, PUSHC, PUSHD1, PUSHD2, PUSHD, CALL, CALLN, LNOT, BNOT, UMINUS,
  338.     LOR, LAND, BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT,
  339.     DIV, MOD, POWER, FACTORIAL, BOOLE, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  340. };
  341.  
  342.  
  343. #define is_jump(operator) ((operator) >=(int)JUMP && (operator) <(int)SF_START)
  344.  
  345.  
  346. enum DATA_TYPES {
  347.     INTGR, CMPLX
  348. };
  349.  
  350.  
  351. enum PLOT_TYPE {
  352.     FUNC, DATA, FUNC3D, DATA3D
  353. };
  354.  
  355. /*XXX - JG */
  356. enum PLOT_STYLE {
  357.     LINES, POINTSTYLE, IMPULSES, LINESPOINTS, DOTS, ERRORBARS, BOXES, BOXERROR, STEPS
  358. };
  359.  
  360. enum JUSTIFY {
  361.     LEFT, CENTRE, RIGHT
  362. };
  363.  
  364. #if !(defined(ATARI)&&defined(__GNUC__)&&defined(_MATH_H)) /* FF's math.h has the type already */
  365. struct cmplx {
  366.     double real, imag;
  367. };
  368. #endif
  369.  
  370.  
  371. struct value {
  372.     enum DATA_TYPES type;
  373.     union {
  374.         int int_val;
  375.         struct cmplx cmplx_val;
  376.     } v;
  377. };
  378.  
  379.  
  380. struct lexical_unit {    /* produced by scanner */
  381.     TBOOLEAN is_token;    /* true if token, false if a value */ 
  382.     struct value l_val;
  383.     int start_index;    /* index of first char in token */
  384.     int length;            /* length of token in chars */
  385. };
  386.  
  387.  
  388. struct ft_entry {        /* standard/internal function table entry */
  389.     char *f_name;        /* pointer to name of this function */
  390.     FUNC_PTR func;        /* address of function to call */
  391. };
  392.  
  393.  
  394. struct udft_entry {                /* user-defined function table entry */
  395.     struct udft_entry *next_udf;         /* pointer to next udf in linked list */
  396.     char udf_name[MAX_ID_LEN+1];         /* name of this function entry */
  397.     struct at_type *at;            /* pointer to action table to execute */
  398.     char *definition;             /* definition of function as typed */
  399.     struct value dummy_values[MAX_NUM_VAR];    /* current value of dummy variables */
  400. };
  401.  
  402.  
  403. struct udvt_entry {            /* user-defined value table entry */
  404.     struct udvt_entry *next_udv; /* pointer to next value in linked list */
  405.     char udv_name[MAX_ID_LEN+1]; /* name of this value entry */
  406.     TBOOLEAN udv_undef;        /* true if not defined yet */
  407.     struct value udv_value;    /* value it has */
  408. };
  409.  
  410.  
  411. union argument {            /* p-code argument */
  412.     int j_arg;                /* offset for jump */
  413.     struct value v_arg;        /* constant value */
  414.     struct udvt_entry *udv_arg;    /* pointer to dummy variable */
  415.     struct udft_entry *udf_arg; /* pointer to udf to execute */
  416. };
  417.  
  418.  
  419. struct at_entry {            /* action table entry */
  420.     enum operators index;    /* index of p-code function */
  421.     union argument arg;
  422. };
  423.  
  424.  
  425. struct at_type {
  426.     int a_count;                /* count of entries in .actions[] */
  427.     struct at_entry actions[MAX_AT_LEN];
  428.         /* will usually be less than MAX_AT_LEN is malloc()'d copy */
  429. };
  430.  
  431.  
  432. /* Defines the type of a coordinate */
  433. /* INRANGE and OUTRANGE points have an x,y point associated with them */
  434. enum coord_type {
  435.     INRANGE,                /* inside plot boundary */
  436.     OUTRANGE,                /* outside plot boundary, but defined */
  437.     UNDEFINED                /* not defined at all */
  438. };
  439.   
  440. #if defined(MSDOS) || defined(_Windows) 
  441. typedef float coordval;        /* memory is tight on PCs! */
  442. #else
  443. typedef double coordval;
  444. #endif
  445.  
  446. struct coordinate {
  447.     enum coord_type type;    /* see above */
  448.     coordval x, y, z;
  449.     coordval ylow, yhigh;    /* ignored in 3d */
  450. #if (defined(_Windows) && !defined(WIN32)) || (defined(MSDOS) && defined(__TURBOC__))
  451.     char pad[10];        /* pad to 32 byte boundary */
  452. #endif
  453. };
  454.  
  455. struct curve_points {
  456.     struct curve_points *next_cp;    /* pointer to next plot in linked list */
  457.     enum PLOT_TYPE plot_type;
  458.     enum PLOT_STYLE plot_style;
  459.     char *title;
  460.     int line_type;
  461.     int point_type;
  462.      int p_max;                    /* how many points are allocated */
  463.     int p_count;                    /* count of points in points */
  464.     struct coordinate GPHUGE *points;
  465. };
  466.  
  467. struct gnuplot_contours {
  468.     struct gnuplot_contours *next;
  469.     struct coordinate GPHUGE *coords;
  470.      char isNewLevel;
  471.      char label[12];
  472.     int num_pts;
  473. };
  474.  
  475. struct iso_curve {
  476.     struct iso_curve *next;
  477.      int p_max;                    /* how many points are allocated */
  478.     int p_count;                    /* count of points in points */
  479.     struct coordinate GPHUGE *points;
  480. };
  481.  
  482. struct surface_points {
  483.     struct surface_points *next_sp;    /* pointer to next plot in linked list */
  484.     enum PLOT_TYPE plot_type;
  485.     enum PLOT_STYLE plot_style;
  486.     char *title;
  487.     int line_type;
  488.     int point_type;
  489.     int has_grid_topology;
  490.     int num_iso_read;  /* Data files only - num of isolines read from file. */
  491.     struct gnuplot_contours *contours;    /* Not NULL If have contours. */
  492.     struct iso_curve *iso_crvs;
  493. };
  494.  
  495. struct TERMENTRY {
  496.     char *name;
  497. #if defined(_Windows) && !defined(WIN32)
  498.     char GPFAR description[80];    /* to make text go in FAR segment */
  499. #else
  500.     char *description;
  501. #endif
  502.     unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
  503.     FUNC_PTR options,init,reset,text,scale,graphics,move,vector,linetype,
  504.         put_text,text_angle,justify_text,point,arrow;
  505. };
  506.  
  507. #ifdef _Windows
  508. #define termentry TERMENTRY far
  509. #else
  510. #define termentry TERMENTRY
  511. #endif
  512.  
  513.  
  514. struct text_label {
  515.     struct text_label *next;    /* pointer to next label in linked list */
  516.     int tag;            /* identifies the label */
  517.     double x,y,z;
  518.     enum JUSTIFY pos;
  519.     char text[MAX_LINE_LEN+1];
  520. };
  521.  
  522. struct arrow_def {
  523.     struct arrow_def *next;    /* pointer to next arrow in linked list */
  524.     int tag;            /* identifies the arrow */
  525.     double sx,sy,sz;        /* start position */
  526.     double ex,ey,ez;        /* end position */
  527.     TBOOLEAN head;            /* arrow has a head or not */
  528. };
  529.  
  530. /* Tic-mark labelling definition; see set xtics */
  531. struct ticdef {
  532.     int type;                /* one of three values below */
  533. #define TIC_COMPUTED 1        /* default; gnuplot figures them */
  534. #define TIC_SERIES 2        /* user-defined series */
  535. #define TIC_USER 3            /* user-defined points */
  536. #define TIC_MONTH 4        /* print out month names ((mo-1)%12)+1 */
  537. #define TIC_DAY 5        /* print out day of week */
  538.     union {
  539.        struct {            /* for TIC_SERIES */
  540.           double start, incr;
  541.           double end;        /* ymax, if VERYLARGE */
  542.        } series;
  543.        struct ticmark *user;    /* for TIC_USER */
  544.     } def;
  545. };
  546.  
  547. /* Defines one ticmark for TIC_USER style.
  548.  * If label==NULL, the value is printed with the usual format string.
  549.  * else, it is used as the format string (note that it may be a constant
  550.  * string, like "high" or "low").
  551.  */
  552. struct ticmark {
  553.     double position;        /* where on axis is this */
  554.     char *label;            /* optional (format) string label */
  555.     struct ticmark *next;    /* linked list */
  556. };
  557.  
  558. /*
  559.  * SS$_NORMAL is "normal completion", STS$M_INHIB_MSG supresses
  560.  
  561.  * printing a status message.
  562.  * SS$_ABORT is the general abort status code.
  563.  from:    Martin Minow
  564.     decvax!minow
  565.  */
  566. #ifdef    vms
  567. #include        <ssdef.h>
  568. #include        <stsdef.h>
  569. #define    IO_SUCCESS    (SS$_NORMAL | STS$M_INHIB_MSG)
  570. #define    IO_ERROR    SS$_ABORT
  571. #endif /* vms */
  572.  
  573.  
  574. #ifndef    IO_SUCCESS    /* DECUS or VMS C will have defined these already */
  575. #define    IO_SUCCESS    0
  576. #endif
  577. #ifndef    IO_ERROR
  578. #define    IO_ERROR    1
  579. #endif
  580.  
  581. /* Some key global variables */
  582. extern TBOOLEAN screen_ok;
  583. extern TBOOLEAN term_init;
  584. extern TBOOLEAN undefined;
  585. extern struct termentry term_tbl[];
  586.  
  587. extern char *alloc();
  588. extern char GPFAR *gpfaralloc();    /* far versions */
  589. extern char GPFAR *gpfarrealloc();
  590. extern void gpfarfree();
  591. /* allocating and managing curve_points structures */
  592. extern struct curve_points *cp_alloc();
  593. extern int cp_extend();
  594. extern int cp_free();
  595. /* allocating and managing surface_points structures */
  596. extern struct surface_points *sp_alloc();
  597. extern int sp_replace();
  598. extern int sp_free();
  599. /* allocating and managing is_curve structures */
  600. extern struct iso_curve *iso_alloc();
  601. extern int iso_extend();
  602. extern int iso_free();
  603.  
  604. /* Windows needs to redefine stdin/stdout functions */
  605. #ifdef _Windows
  606. #include "win/wtext.h"
  607. #endif
  608.